package com.example.demo.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.example.demo.DemoOneFragment;
import com.example.demo.DemoTwoFragment;
import com.example.demo.fragment.GameFragment;
import com.example.demo.fragment.SoftWareFragment;

public class ViewPagerDemoAdapter extends FragmentPagerAdapter {
    private static final String [] PAGE_TITLE = {"游戏榜", "软件榜"};

    public ViewPagerDemoAdapter(@NonNull FragmentManager fm) {
        super(fm);
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return position % 2 == 0 ? new GameFragment() : new SoftWareFragment();
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return PAGE_TITLE [position];
    }
}
